<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../style/main.css" type="text/css" rel="stylesheet">
        <link href="../style/my_account.css" type="text/css" rel="stylesheet">
        <script type="text/javascript" src="../script/jquery-1.8.2.js"></script>
        <script type="text/javascript" src="../script/js1.js"></script>
</head>

<body>

 <header>
        <?php
        session_start();
        mysql_connect("localhost:3306", "root", "16886611");
        mysql_select_db("digitalsales");
        if(isset($_GET["action"])){
            if($_GET["action"]=="logout"){
               $_SESSION["username"]=NULL;
            }
        }
        if(!isset($_SESSION["username"])||$_SESSION["username"]==NULL){
        echo '<ul>
                <li id="login">
                  <p>Log in</p>
                </li>
                 <li>
                    <p><a href="../PhpProject1/register/register.php">Register</a></p>
                  </li>
                </ul>';
        }else{
            echo '<ul>
                <li id="logout">
                  <p><a href="../index.php?action=logout">Log out</a></p>
                </li>
                 <li>
                    <p><a href="../myAccount/myAccount.php">My Account</a></p>
                  </li>
                  <li>
                    <p><a href="../myAccount/order.php">My Orders</a></p>
                  </li>
                  <li>
                    <p>Welcome back,'.$_SESSION["username"].'!</p>
                  </li>
                </ul>';
        }
        
        ?>
        </header>

<div id="my_account" class="MainPanel">

My Account<br />

</div>

    <div id="purchase_history" class="MainPanel">
    Purchase History<br />
    </div>
    
    <div id="purchase_table" class="MainPanel">
    <table>
        
    <tr>
    <th>Product</th>
    <th>Store</th>
    <th>Price</th>
    <th>Quantity</th>
    <th>Date</th>
    </tr>
    
    <tr>
    
        <td class="product">
        <?php
        $query=mysql_query("SELECT P.NAME
            FROM products P, transactions T
            WHERE T.CUSTOMER = '".$_SESSION['username']."' and T.PRODUCT = P.PRODUCTID
            ORDER BY DATE desc");
	while( $query_row = mysql_fetch_array( $query ) ){
	echo($query_row['NAME'].'<br><br>');
        }
        ?>
        </td>
    
        <td class="store">
        <?php
        $query=mysql_query("SELECT S.NAME
            FROM stores S, transactions T
            WHERE T.CUSTOMER = '".$_SESSION['username']."' and T.STORE = S.STOREID
            ORDER BY DATE desc");
	while( $query_row=mysql_fetch_array($query) ){
	echo($query_row['NAME'].'<br><br>');
        }
        ?>
        </td>
    
        <td>
        <?php
        $query=mysql_query("SELECT T.PRICE
            FROM transactions T
            WHERE T.CUSTOMER = '".$_SESSION['username']."'
            ORDER BY DATE desc");
	while( $query_row=mysql_fetch_array($query) ){
	echo($query_row['PRICE'].'<br><br>');
        }
        ?>
        </td>
    
        <td>
        <?php
        $query=mysql_query("SELECT T.QUANTITY
            FROM transactions T
            WHERE T.CUSTOMER = '".$_SESSION['username']."'
            ORDER BY DATE desc");
	while( $query_row=mysql_fetch_array($query) ){
	echo($query_row['QUANTITY'].'<br><br>');
        }
        ?>
        </td>

    <td>
        <?php
        $query=mysql_query("SELECT T.DATE
            FROM transactions T
            WHERE T.CUSTOMER = '".$_SESSION['username']."'
            ORDER BY DATE desc");
	while( $query_row=mysql_fetch_array($query) ){
	echo($query_row['DATE'].'<br><br>');
        }
        ?>
        </td>
    </tr>
    
    </table>
   
    </div>
    
    
    <div id="account_settings" class="MainPanel">
    Account Settings<br />
    </div>

    <div id="update_info" class="MainPanel">
        <a href="../myAccount/update_info.php">Change my password & Update personal information</a><br />
    </div>
    
</body>

</html>